﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LDSP.BRL;
using LDSP.Util;

namespace LDSP.UI.EnterpriseGroupAdmin
{
    public partial class EGSystemSetting : LDSP.BRL.BaseEnterpriseGroupAdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (this.RB())
                {
                    if (!IsPostBack)
                    {
                        this.InitDataSelect();
                    }
                }
            }
            catch (Exception ex)
            {
                this.HandlerException(ex);
            }
        }

        protected bool RB()
        {
            return this.AllowEnterpriseUser();
        }

        protected void InitDataSelect()
        {
            this.txt_CodificationActiveAlert.Text = this.LoginUser.Enterprise.EnterpriseConfig.CodificationActiveAlert > 0 ? this.LoginUser.Enterprise.EnterpriseConfig.CodificationActiveAlert.ToString() : string.Empty;
            this.txt_TaskPlanAlert.Text = this.LoginUser.Enterprise.EnterpriseConfig.TaskPlanAlertDays > 0 ? this.LoginUser.Enterprise.EnterpriseConfig.TaskPlanAlertDays.ToString() : string.Empty;

            this.rbtnAll.Checked = true;
            this.rbtnSpecified.Checked = this.LoginUser.Enterprise.EnterpriseConfig.TaskPlanAlertType == this.rbtnSpecified.Text;
        }

        protected void ValidateDataBefore()
        {
        }

        protected void ValidateDataAfter()
        {

        }
        protected void SetData()
        {
            this.ValidateDataBefore();
            this.LoginUser.Enterprise.EnterpriseConfig.CodificationActiveAlert = this.GetInt(this.txt_CodificationActiveAlert.Text);
            this.LoginUser.Enterprise.EnterpriseConfig.TaskPlanAlertDays = this.GetInt(this.txt_TaskPlanAlert.Text);
            this.LoginUser.Enterprise.EnterpriseConfig.TaskPlanAlertType = this.rbtnAll.Checked ? this.rbtnAll.Text : this.rbtnSpecified.Text;

            this.ValidateDataAfter();
        }

        protected void btn_ok_Click(object sender, EventArgs e)
        {
            try
            {
                this.SetData();
                this.JSAlert("更新成功！");
                this.InitDataSelect();
            }
            catch (TemplateValidateException ex)
            {
                this.JSAlert(ex.Message);
            }
            catch (Exception ex)
            {
                this.HandlerException(ex);
            }
        }
    }

}